package LC;

/**
 * https://leetcode.com/problems/same-tree/description/
 * Given two binary trees, write a function to check if they are equal or not.
 * Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
 */
public class LC_100_SameTree_BinaryTree_Recur {
    public static void main(String[] args) {
        TreeNode h1 = new TreeNode(1);
        h1.left = new TreeNode(2);
        System.out.println(Solution.isSameTree(h1, null));
    }

    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    static class Solution {
        static boolean isSameTree(TreeNode p, TreeNode q) {
            return p == null && q == null || p != null && q != null && p.val == q.val && isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
        }
    }
}
